#include<stdio.h>
#include<stdlib.h>
#include<assert.h>

struct elem_t {
	int value;
	int min;
	struct elem_t * next;
};

struct stack_t {
	struct elem_t * top;
};

void push(stack_t * st, int v) {
	elem_t * e = (elem_t *)malloc(sizeof(elem_t));
	e->value = v;
	e->next = NULL;

	if (st->top == NULL) {
		e->min = v;
		st->top = e;
	} else {
		if (e->value < st->top->min)
			e->min = e->value;
		else
			e->min = st->top->min;
		e->next = st->top;
		st->top = e;
	}
}

void pop(stack_t * st) {
	if (st->top == NULL)
		return;

	elem_t * e = st->top;
	st->top = st->top->next;
	free(e);
}

int min(stack_t * st) {
	assert(st->top);
	return st->top->min;
}

int main() {
	struct stack_t st;
	st.top = NULL;

	push(&st, 10);
	push(&st, 6);
	push(&st, 4);
	push(&st, 14);
	push(&st, 12);
	push(&st, 2);

	pop(&st);
	printf("%d\n", min(&st));
	pop(&st);
	printf("%d\n", min(&st));
	pop(&st);
	printf("%d\n", min(&st));
	pop(&st);
	printf("%d\n", min(&st));
	pop(&st);
	printf("%d\n", min(&st));
	return 0;
}
